package com.qfedu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.TQuestionDao;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.TQuestion;
import com.qfedu.entity.User;
import com.qfedu.entity.Week;
import com.qfedu.service.TQuestionService;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/OaNew")
public class TQuestionController {

    @Autowired
    private TQuestionService tQuestionService;

    /**
     * 添加笔记
     * @param
     * @param
     * @return
     */
    @RequestMapping("/addNote.do")
    public ResponseData addQuestionNote(TQuestion tQuestion , HttpServletRequest request){

        ResponseData responseData = new ResponseData();

        HttpSession session = request.getSession();

        User user = (User) session.getAttribute("user");

        String no = user.getNo();

        tQuestion.setU_no(no);

        int i = tQuestionService.addQuestionNote(tQuestion);

        if (i > 0) {
            responseData.setCode(0);
            responseData.setMsg("success");
        } else {
            responseData.setCode(1);
            responseData.setMsg("fail");
            responseData.setMsg("上传成功");
        }

        return responseData;
    }

    /**
     * 添加代码
     * @param
     * @param
     * @return
     */
    @RequestMapping("/addCode.do")
    public ResponseData addQuestionCode(TQuestion tQuestion, HttpServletRequest request){

        ResponseData responseData = new ResponseData();

        HttpSession session = request.getSession();

        User user = (User) session.getAttribute("user");

        String no = user.getNo();

        tQuestion.setU_no(no);

        int i = tQuestionService.addQuestionCode(tQuestion);

        if (i > 0) {
            responseData.setCode(0);
            responseData.setMsg("success");
        } else {
            responseData.setCode(1);
            responseData.setMsg("fail");
            responseData.setMsg("上传成功");
        }

        return responseData;
    }

    /**
     * 新增资源
     * @param tQuestion
     * @return
     */
    @RequestMapping("/savequestion.do")
    public ResponseData addQuestion(TQuestion tQuestion ,HttpServletRequest request){
        ResponseData responseData = new ResponseData();

        HttpSession session = request.getSession();

        User user = (User) session.getAttribute("user");

        String no = user.getNo();

        tQuestion.setU_no(no);

        int i = tQuestionService.addQuestion(tQuestion);

        if (i > 0) {
            responseData.setCode(0);
            responseData.setMsg("success");
        } else {
            responseData.setCode(1);
            responseData.setMsg("fail");
        }

        return responseData;

    }


}
